<include file="public@header" />
<style>.expander{margin-left: -20px;}</style>
</head>
<body>
	<div class="wrap js-check-wrap">
		<div class="main-title">
			<h4>权限设置</h4>
		</div>
		<form class="js-ajax-form margin-top-20"  action="{:url('authority')}" method="post">
			<div class="table_full">
				<table class="table table-bordered" id="authrule-tree">
					<tbody>
						{$category}
					</tbody>
				</table>
				<table class="table" id="authrule-department">
					<tbody>
						<volist name="items" id="vo">
							<tr>
								<td>{$vo.name}：<select class="form-control" name="user_item[{$vo.id}]"><option value="0">默认</option><volist name="vo.items" id="item"><option value="{$item.id}" <volist name="role_items" id="k"><if condition="$k['config_id'] == $vo['id'] && $k['item_id'] == $item['id']">selected</if></volist>>{$item.name}</option></volist></select></td>
							</tr>
						</volist>
						<tr>
							<td><input type="checkbox" name="data_to_all_user" <Notempty name="roleDepartment.data_to_all_user">checked</Notempty> /> 数据分配给所有人</td>
						</tr>
						<tr>
							<td><input type="checkbox" name="show_department" <Notempty name="roleDepartment.show_department">checked</Notempty> /> 管理部门所有数据</td>
						</tr>
						<tr>
							<td><input type="checkbox" name="company_manage" <Notempty name="roleDepartment.company_manage">checked</Notempty> /> 管理公司所有数据</td>
						</tr>
					</tbody>
				</table>
			</div>
			<div class="form-actions">
				<input type="hidden" name="roleId" value="{$roleId}" />
				<button class="btn btn-primary js-ajax-submit" type="submit">{:lang('SAVE')}</button>
				<a class="btn btn-default" href="javascript:history.back(-1);">返回</a>
			</div>
		</form>
	</div>
	<script src="__STATIC__/js/admin.js"></script>
	<script type="text/javascript">
	$(document).ready(function () {
		Wind.css('treeTable');
	    Wind.use('treeTable', function () {
	        $("#authrule-tree").treeTable({
	            indent: 20
	        });
	    });
	});

    function checknode(obj) {
        var chk = $("input[type='checkbox']");
        var count = chk.length;

        var num = chk.index(obj);
        var level_top = level_bottom = chk.eq(num).attr('level');
        for (var i = num; i >= 0; i--) {
            var le = chk.eq(i).attr('level');
            if (le <level_top) {
                chk.eq(i).prop("checked", true);
                var level_top = level_top - 1;
            }
        }
        for (var j = num + 1; j < count; j++) {
            var le = chk.eq(j).attr('level');
            if (chk.eq(num).prop("checked")) {

                if (le > level_bottom){
                    chk.eq(j).prop("checked", true);
                }
                else if (le == level_bottom){
                    break;
                }
            } else {
                if (le >level_bottom){
                    chk.eq(j).prop("checked", false);
                }else if(le == level_bottom){
                    break;
                }
            }
        }
    }
	</script>
</body>
</html>